//
//  LCWTabBar.swift
//  MyWB
//
//  Created by 李成万 on 16/6/25.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit

protocol ComposeBtnDelegate : NSObjectProtocol{
    func composeBtnClick()
}

class LCWTabBar: UITabBar {


    weak var LCWDelegate:ComposeBtnDelegate?
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        addSubview(composeBtn)
        
        let widtH = SCREENW / 5
        
        var index : CGFloat = 0
        for value in subviews{
            if value.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                value.frame.origin.x = index * widtH
                value.frame.size.width = widtH
                
                index++
                
                if index == 2 {
                    index++
                }
                
            }
            
            composeBtn.center.x = self.frame.width * 0.5
            composeBtn.center.y = self.frame.height * 0.5
        }
        
        
    }
    
    
    private lazy var composeBtn : UIButton = {
        let button = UIButton(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
        button.addTarget(self, action: "btnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        button.sizeToFit()
        return button
    }()
    
    @objc private func btnClick(){
//        print("dianjile")
        LCWDelegate?.composeBtnClick()
    }
}
